//
//  FGChatKit.h
//  FGChatKit
//
//  Created by feige on 2023/4/25.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "FGChatMessageModel.h"
#import "FGConfigModel.h"

/// 通用回调
typedef void (^FGChatKitCommonCallBlock)(NSInteger code, NSString *msg, id data);

@protocol FGChatKitDelegate <NSObject>
@optional
/**
 * 收到进入房间邀请
 * 收到此回调打开会话页面
 */
- (void)chatKitDidReceiveEnterRoomInvitation:(NSString *)roomId;
/**
 * 加入房间失败
 * @param code  错误码
 * @param msg   错误信息
 */
- (void)chatKitEnterRoomFailure:(NSInteger)code msg:(NSString *)msg;
/**
 * 登录信息失效，收到此回调需重新登录SDK
 */
- (void)chatKitLoginInvalid;
/**
 * 收到消息
 */
- (void)chatKitDidReceiveMessage:(FGChatMessageModel *)message;
/**
 * 收到结束会话
 */
- (void)chatKitDidReceiveEndSession;
/**
 * 收到消息已读回执
 */
- (void)chatKitDidReceiveReadReceipt:(NSString *)mid;
/**
 * 收到撤回消息
 */
- (void)chatKitDidReceiveRevokeMessage:(NSString *)mid;
/**
 * 收到排队消息回调
 * @param queueNum 排队人数
 */
- (void)chatKitDidReceiveQueue:(NSInteger)queueNum;
@end

@interface FGChatKit : NSObject
/// 模板数据
@property (nonatomic, strong, readonly) NSDictionary *templateData;
/// 是否测试环境，默认NO（注：该属性一般不设置）
@property (nonatomic, assign) BOOL isTest;
/// 主题列表
@property (nonatomic, strong, readonly) NSArray<FGTopicsModel *> *topicsModels;
/// 选中的主题
@property (nonatomic, strong, readonly) FGTopicsModel *selectedTopicsModel;
/// 房间id
@property (nonatomic, copy, readonly) NSString *roomId;
/// 站点id
@property (nonatomic, strong, readonly) NSNumber *websiteId;
/// 聊天中自己的id
@property (nonatomic, copy, readonly) NSString *chatSelfId;
/// 公司id
@property (nonatomic, strong, readonly) NSNumber *companyId;

/**
 * 单例
 */
+ (instancetype)sharedKit;

/**
 * 启动
 * @param idMark    站点编号标记
 * @param callBlock 回调
 */
- (void)start:(NSString *)idMark
    callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 结束
 */
- (void)end;

/**
 * 添加多播委托
 * 多播委托：不同于常规代理回调，多个地方添加了代理都能回到回调
 */
- (void)addDelegate:(id<FGChatKitDelegate>)delegate
      delegateQueue:(dispatch_queue_t)queue;

/**
 * 移除多播委托
 * 多播委托：不同于常规代理回调，多个地方添加了代理都能回到回调
 */
- (void)removeDelegate:(id<FGChatKitDelegate>)delegate;

/**
 * 触发登录失效代理回调
 * 注：该方法不用调用
 */
- (void)triggerLoginInvalid;

/**
 * 获取离线消息（20条）
 * data数据类型为NSArray<FGChatMessageModel *>
 * @param roomId    房间id
 * @param beginTime 开始时间（格式yyyy-MM-dd HH:mm:ss）
 * @param type      1、之前 2、之后
 */
- (void)getOfflineMessage:(NSString *)roomId
                beginTime:(NSString *)beginTime
                     type:(NSInteger)type
                callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 获取单个模板json字符串
 * @param tempType  模板类型
 * @param tempId    模板id
 */
- (NSString *)singleTemplateJsonStr:(FGTemplateType)tempType
                             tempId:(NSNumber *)tempId;

/**
 * 查询访客是否在黑名单
 * data数据类型为JSON对象
 */
- (void)getIsVisitorBlack:(FGChatKitCommonCallBlock)callBlock;

/**
 * 获取座席信息
 * data数据类型为JSON对象
 */
- (void)getSeatInfo:(FGChatKitCommonCallBlock)callBlock;

/**
 * 发送消息
 */
- (void)sendMessage:(FGChatMessageModel *)messageModel
          callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 发送系统消息
 * @param content   消息内容
 * @param room      房间号
 */
- (void)sendSystemMessage:(NSString *)content
                     room:(NSString *)room
                callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 发送单条回执
 * @param mid   消息id
 * @param from  来自谁
 */
- (void)messageReceipt:(NSString *)mid
                  from:(NSString *)from
             callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 发送整个房间消息回执
 * @param room  房间号
 */
- (void)roomMessageReceipt:(NSString *)room
                 callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 撤回消息
 * @param mid   消息id
 * @param room  房间号
 */
- (void)revokeMessage:(NSString *)mid
                 room:(NSString *)room
            callBlock:(FGChatKitCommonCallBlock)callBlock;

/**
 * 选择主题
 * @param topicsId 主题id
 */
- (void)selectTopicsForId:(NSNumber *)topicsId;

/**
 * 进入房间
 * 进入成功会回调<FGChatKitDelegate>中chatKitDidReceiveEnterRoomInvitation:方法
 */
- (void)enterConversation;

/**
 * 上传图片
 */
- (void)uploadImage:(UIImage *)image
            success:(void(^)(BOOL succeed, NSString *msg, NSString *url))success
            failure:(void(^)(void))failure;

/**
 * 上传文件
 */
- (void)uploadFlieData:(NSData *)fileData
              fileName:(NSString *)fileName
               success:(void(^)(BOOL succeed, NSString *msg, NSString *url))success
               failure:(void(^)(void))failure;

/**
 * 提交表单
 * @param fromDict 表单数据 格式：{"CompanyName": "", ...}
 */
- (void)submitFrom:(NSDictionary *)fromDict
         callBlock:(FGChatKitCommonCallBlock)callBlock;

@end
